import gevent
from gevent import monkey
import requests

# 打补丁，把标准库中的阻塞操作转为非阻塞
monkey.patch_all()

def work1():
    for _ in range(3):
        print("这是work1")
        response = requests.get("http://www.baidu.com")
        print("work1 - 响应状态码：", response.status_code)
        gevent.sleep(0.1)   # 使用gevent.sleep模拟 非阻塞

def work2():
    for _ in range(3):
        print("这是work2")
        response = requests.get("http://www.baidu.com")
        print("work2 - 响应状态码：", response.status_code)
        gevent.sleep(0.1)

# 创建协程
g1 = gevent.spawn(work1)
g2 = gevent.spawn(work2)

g1.join()
g2.join()

